package com.serviceprovider.business.module.report.valueobjects;

//~--- non-JDK imports --------------------------------------------------------

import com.serviceprovider.business.module.sp.transaction.model.TransactionUserAmount;

//~--- JDK imports ------------------------------------------------------------

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class TransactionsReportRecord {
    private Integer                     amount;
    private String                      customerName;
    private int                         selfFee;
    private double                      serviceFee;
    private String                      ssn;
    private int                         totalByRow;
    private List<TransactionUserAmount> transactionUserAmounts;

    public TransactionsReportRecord() {}

    public TransactionsReportRecord(String ssn, String customerName, int selfFee) {
        this.ssn          = ssn;
        this.customerName = customerName;
        this.selfFee      = selfFee;
    }

    public String getSsn() {
        return ssn;
    }

    public void setSsn(String ssn) {
        this.ssn = ssn;
    }

    public String getCustomerName() {
        return customerName;
    }

    public void setCustomerName(String customerName) {
        this.customerName = customerName;
    }

    public int getSelfFee() {
        return selfFee;
    }

    public void setSelfFee(int selfFee) {
        this.selfFee = selfFee;
    }

    public int getTotalByRow() {
        return totalByRow;
    }

    public void setTotalByRow(int total) {
        this.totalByRow = total;
    }

    public void setAmount(Integer amount) {
        this.amount = amount;
    }

    public Integer getAmount() {
        return amount;
    }

    public double getServiceFee() {
        return serviceFee;
    }

    public void setServiceFee(double serviceFee2) {
        this.serviceFee = serviceFee2;
    }

    public void setTransactionUserAmounts(List<TransactionUserAmount> transactionUserAmounts) {
        this.transactionUserAmounts = transactionUserAmounts;
    }

    public List<TransactionUserAmount> getTransactionUserAmounts() {
        return transactionUserAmounts;
    }

    public Map<Integer, Integer> getAmountOfUser() {

        // FIXME: [Performance] amounts map will be created so many times
        Map<Integer, Integer> amounts = new HashMap<Integer, Integer>();

        for (TransactionUserAmount transUserAmount : transactionUserAmounts) {
            amounts.put(transUserAmount.getUserId(), transUserAmount.getAmount());
        }

        return amounts;
    }

    public double getTotalAll() {
        double result = serviceFee + selfFee;

        for (TransactionUserAmount transAmount : transactionUserAmounts) {
            result += transAmount.getAmount();
        }

        return result;
    }

    public double getCustomerBalance() {
        return amount - getTotalAll();
    }
}



